from read_excel_save_db import save_public_area
from read_excel_save_db import query_by_country_abbreviation
from read_excel_save_db import query_by_area_name_and_parent_id
from read_excel_save_db import PublicAreaObject
from read_excel_save_db import read_excel_save_db


def read_db_save_db():
    country_abbreviation = "US"
    country_name = "美国"
    country_english_name = "America"
    country_phone_code = "001"
    country_currency = "USD"
    time_zone = "UTC-5"
    distinct_name = "市辖区"
    original_area_id = 1000000
    city_list = query_by_country_abbreviation(area_depths=2, country_abbreviation=country_abbreviation)
    print(f"city_list.size(){len(city_list)}")

    for city in city_list:
        print(f"   - city:{city}")
        distinct = query_by_area_name_and_parent_id(distinct_name, 3, country_abbreviation, city.area_id)
        if distinct is None:
            distinct = PublicAreaObject(None, None, None, None, distinct_name, None, country_abbreviation,
                                        country_name, country_english_name, country_phone_code, country_currency,
                                        time_zone)
            distinct.area_depths = 3
            distinct.parent_area_id = city.area_id
            save_public_area(distinct, original_area_id)
            distinct_id = distinct.area_id
        else:
            distinct_id = distinct.area_id
        original_area_id = distinct_id + 1


# 导入美国数据
# read_db_save_db()

# 导入泰国数据
read_excel_save_db()